package com.gdk.service.impl;

import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gdk.dao.ArticleDao;
import com.gdk.dao.CategoryDao;
import com.gdk.dao.GoodsDao;
import com.gdk.dao.LoginDao;
import com.gdk.dao.NavigationDao;
import com.gdk.service.ArticleService;
import com.gdk.service.CategoryService;
import com.gdk.service.GoodsService;
import com.gdk.service.LoginService;
import com.gdk.service.NavigationService;
import com.gdk.utils.Md5Utils;
import com.gdk.utils.XVDateUtils;
import com.google.gson.Gson;


/**
 * 商品业务处理
 * */
@Service("GoodsService")
public class GoodsServiceImpl implements GoodsService {
	@Autowired
    private GoodsDao goodsDao;

	 @Override
	public List<Map<String, Object>> selectAllGoods(Map<String,Object> map) {
		return goodsDao.selectAllGoods(map);
	}
	
	 @Override
	public int addGoods(Map<String, Object> map) {
		return goodsDao.addGoods(map);
	}
	@Override
	public Map<String, Object> selectGoodsDetails(Map<String, Object> map) {
		Map<String,Object> goodsDetails = goodsDao.selectGoodsDetails(map);
		//时间格式化
		
		if(goodsDetails.get("rg_atime") !=null && !"".equals(goodsDetails.get("rg_atime").toString())) {
			
			//开始时间
			String rg_atime = XVDateUtils.MillisFormat(Integer.parseInt(goodsDetails.get("rg_atime").toString()));
			//结束时间
			String rg_etime = XVDateUtils.MillisFormat(Integer.parseInt(goodsDetails.get("rg_etime").toString()));
			goodsDetails.put("rg_atime", rg_atime);
			goodsDetails.put("rg_etime", rg_etime);
		}
		
		//规格格式化
		Gson gson = new Gson();
		Map<String,Object> spec = new HashMap<String,Object>();
		spec = gson.fromJson(goodsDetails.get("rg_specifications").toString(), spec.getClass());
		goodsDetails.put("spec", spec);
		return goodsDetails;
	}
	@Override
	public int updateGoodsDetails(Map<String, Object> map) {
		return goodsDao.updateGoodsDetails(map);
	}
	@Override
	public int addGoodsPhoto(Map<String, Object> map) {
		return goodsDao.addGoodsPhoto(map);
	}
	
	@Override
	public int addTreeReceipt(Map<String, Object> map) {
		return goodsDao.addTreeReceipt(map);
	}
	@Override
	public List<Map<String, Object>> selectAllReceiptStatus() {
		return goodsDao.selectAllReceiptStatus();
	}
	@Override
	public List<Map<String, Object>> selectAllReceipt(Map<String, Object> map) {
		return goodsDao.selectAllReceipt(map);
	}
	@Override
	public int updateReceiptDetails(Map<String, Object> map) {
		return goodsDao.updateReceiptDetails(map);
	}
	@Override
	public List<Map<String, Object>> selectAllDs(Map<String, Object> map) {
		return goodsDao.selectAllDs(map);
	}
	@Override
	public List<Map<String, Object>> selectAllTreeAndUser(Map<String, Object> map) {
		return goodsDao.selectAllTreeAndUser(map);
	}
	@Override
	public int addTreeReceiptAndUser(Map<String, Object> map) {
		return goodsDao.addTreeReceiptAndUser(map);
	}
	@Override
	public List<Map<String, Object>> selectAllTreeShouhuo(Map<String, Object> map) {
		return goodsDao.selectAllTreeShouhuo(map);
	}
	@Override
	public int addTreeHandle(Map<String, Object> map) {
		return goodsDao.addTreeHandle(map);
	}
	@Override
	public List<Map<String, Object>> selectAllHandleByTree(Map<String, Object> map) {
		return goodsDao.selectAllHandleByTree(map);
	}
	@Override
	public List<Map<String, Object>> selectAllApplyDaishou(Map<String, Object> map) {
		return goodsDao.selectAllApplyDaishou(map);
	}
	@Override
	public int updateApplyDaishouStatus(Map<String, Object> map) {
		return goodsDao.updateApplyDaishouStatus(map);
	}
	@Override
	public int addTreeBaoxian(Map<String, Object> map) {
		return goodsDao.addTreeBaoxian(map);
	}
	@Override
	public int updateBaoxianDetails(Map<String, Object> map) {
		return goodsDao.updateBaoxianDetails(map);
	}
	@Override
	public List<Map<String, Object>> selectAllBaoxian(Map<String, Object> map) {
		return goodsDao.selectAllBaoxian(map);
	}
	@Override
	public int updateUserAndTreeDetails(Map<String, Object> map) {
		return goodsDao.updateUserAndTreeDetails(map);
	}
	@Override
	public List<Map<String, Object>> selectAllFahuo(Map<String, Object> map) {
		return goodsDao.selectAllFahuo(map);
	}
	@Override
	public int updateFahuoDetails(Map<String, Object> map) {
		return goodsDao.updateFahuoDetails(map);
	}
	@Override
	public Map<String, Object> selectRecognizeTreeByTree(Map<String, Object> map) {
		return goodsDao.selectRecognizeTreeByTree(map);
	}
	@Override
	public Map<String, Object> selectNowQyByQy(Map<String, Object> map) {
		return goodsDao.selectNowQyByQy(map);
	}
	@Override
	public int addFahuoDetails(Map<String, Object> map) {
		return goodsDao.addFahuoDetails(map);
	}
	@Override
	public int addGoodsStock(Map<String, Object> map) {
		return goodsDao.addGoodsStock(map);
	}
	@Override
	public int addTreeGoodsDaishou(Map<String, Object> map) {
		return goodsDao.addTreeGoodsDaishou(map);
	}
	@Override
	public int addTreeGoodsDaishouOrder(Map<String, Object> map) {
		return goodsDao.addTreeGoodsDaishouOrder(map);
	}
	@Override
	public List<Map<String, Object>> selectAllApplyDaishouByUser() {
		return goodsDao.selectAllApplyDaishouByUser();
	}
	@Override
	public List<Map<String, Object>> selectAllDaishouOrderByUser(Map<String, Object> map) {
		return goodsDao.selectAllDaishouOrderByUser(map);
	}
	@Override
	public List<Map<String, Object>> selectAllDaishouOrder(Map<String, Object> map) {
		return goodsDao.selectAllDaishouOrder(map);
	}
}
